//
//  QJudgeDetailsVC.m
//  QoilPublic
//
//  Created by 杨凯 on 16/7/13.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QJudgeDetailsVC.h"
#import "QJudgeTopCell.h"
#import "QJudgeBottomCell.h"
@interface QJudgeDetailsVC ()<UITableViewDataSource,UITableViewDelegate>

@end
@implementation QJudgeDetailsVC{

    UITableView *_tableView;
    NSDictionary *_dataDic;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"评价详情";
    [self createTableView];
    [self requestData];
}

#pragma mark --- createTableView
- (void)createTableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    
    [_tableView registerNib:[UINib nibWithNibName:@"QJudgeTopCell" bundle:nil] forCellReuseIdentifier:@"QJudgeTopCell"];
}

#pragma mark --- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row == 0){
        QJudgeTopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QJudgeTopCell" forIndexPath:indexPath];
        if(_dataDic){
            cell.dataDic = _dataDic;
        }
        cell.isClick = NO;
        return cell;
    }else{
        static NSString *identify = @"cell";
        QJudgeBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
        if(!cell){
            cell = [[QJudgeBottomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
        }
        cell.isClick = NO;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if(_dataDic){
            cell.dataDic = _dataDic;
        }
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        return 230;
    }else{
        QJudgeBottomCell *cell = (QJudgeBottomCell *)[self tableView:_tableView cellForRowAtIndexPath:indexPath];
        return cell.height;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

#pragma mark --- tableViewDelegate
- (void)requestData{
    NSString *url = [QParamService urlWithAction:@"selUserEvaluatetanker"];
    NSDictionary *param = [QParamService judgeDetailorderId:self.orderId];
    [QViewUtility showMBHudToView:self.view hideBg:NO];
    [[QHttpManager sharedManager] POST:url parameterMD5:param completion:^(NSData *data, NSDictionary *dict, NSError *error) {
        [QViewUtility hideMBHudToView:self.view];
        if(error){
            return ;
        }
        QBaseModel *basModel = [QBaseModel objectFromDict:dict];
        if([basModel.result isEqualToString:@"success"]){
            _dataDic = basModel.items;
            [_tableView reloadData];
        }else{
            [QViewUtility showAlertViewWithImage:[UIImage imageNamed:@"cry_image"] content:basModel.errMsg btnTitle:showAlertBtnTitle type:1 myBlock:^{}];
        }        
    }];
}



@end
